import { http } from '@/utils/request'
import type {
  ListByUserMessageType,
  ListNoticeParams,
  ListUserAllMessageParams,
  MessageTargetParams,
  MessageTargetType,
  NoticeType
} from './model'

/**
 * 获取通知公告
 * @param params
 */
export const getNoticeList = (params: ListNoticeParams) => {
  return http.request<PageResult<NoticeType>>('get', '/message', { params })
}

/**
 * 获取用户消息
 * @param isRead 是否已读
 */
export const getByUserMessageAPI = (isRead: boolean) => {
  return http.request<ListByUserMessageType[]>('get', '/message/user', { params: { isRead } })
}

/**
 * 获取当前登录用户全部消息
 * @param params
 */
export const getUserAllMessageAPI = (params: ListUserAllMessageParams) => {
  return http.request<PageResult<ListByUserMessageType>>('get', '/message/user/all', { params })
}

/**
 * 新增通知公告
 * @param data 提交数据
 * @constructor
 */
export const AddNoticeAPI = (data: NoticeType) => http.request('post', '/message', { data })

/**
 * 更新通知公告
 * @param id
 * @param data 提交数据
 * @constructor
 */
export const updateNoticeAPI = (id: number, data: NoticeType) =>
  http.request('put', `/message/${id}`, { data })

/**
 * 撤销通知公告
 * @param id
 */
export const revokedNoticeAPI = (id: number) => http.request('put', `/message/revoked/${id}`)

/**
 * 删除通知公告
 * @param id
 */
export const deleteNoticeAPI = (id: number) => http.request('delete', `/message/${id}`)

/**
 * 已读通知
 * @param ids id集合
 */
export const readNoticeAPI = (ids: number[]) =>
  http.request('post', `/message/read`, { data: { ids } })

/**
 * 获取通知目标
 * @param mid 消息ID
 * @param params 请求参数
 */
export const getMessageTargetsAPI = (mid: number, params: MessageTargetParams) => {
  return http.request<PageResult<MessageTargetType>>('get', `/message/targets/${mid}`, { params })
}
